<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>研学港 Researchopia</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            width: 100%;
            height: 100vh;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
            background: #f8f9fa;
            overflow: hidden;
        }
        
        .sidebar-header {
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            display: flex;
            align-items: center;
            padding: 0 16px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        
        .header-content {
            display: flex;
            align-items: center;
            gap: 12px;
            width: 100%;
        }
        
        .logo {
            width: 32px;
            height: 32px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
            font-weight: bold;
            color: white;
        }
        
        .title-group {
            flex: 1;
        }
        
        .title {
            font-size: 16px;
            font-weight: 600;
            line-height: 1.2;
        }
        
        .subtitle {
            font-size: 11px;
            opacity: 0.8;
            line-height: 1.2;
        }
        
        .status-indicator {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #9ca3af; /* 默认未知/未检测 */
        }
        .status-indicator.ok {
            background: #10b981; /* 绿色：可达 */
            animation: pulse 2s infinite;
        }
        .status-indicator.fail {
            background: #ef4444; /* 红色：不可达 */
            animation: none;
        }
        
        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }
        
        /* DOI 信息条 */
        .info-bar {
            background: #fff;
            border-bottom: 1px solid #e5e7eb;
            padding: 10px 12px;
        }
        .doi-card {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-left: 4px solid #667eea;
            border-radius: 6px;
            padding: 10px 12px;
        }
        .doi-left { display:flex; align-items:center; gap:8px; flex:1; min-width:0; }
        .doi-label { font-size:12px; color:#6b7280; }
        .doi-code { font-size:12px; color:#111827; background:#eef2ff; padding:2px 6px; border-radius:4px; max-width: 260px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:inline-block; }
        .doi-source { font-size:11px; color:#10b981; background:#ecfdf5; padding:2px 6px; border-radius:999px; }
        .doi-source.dim { color:#6b7280; background:#f3f4f6; }
        .copy-btn { background:#667eea; color:#fff; border:none; padding:6px 10px; border-radius:4px; font-size:12px; cursor:pointer; }
        .copy-btn:hover { background:#5a67d8; }

        .iframe-container {
            width: 100%;
            height: calc(100vh - 60px - 52px);
            position: relative;
        }
        
        .iframe-container iframe {
            width: 100%;
            height: 100%;
            border: none;
            background: white;
        }
        
        .loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: white;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            z-index: 10;
        }
        
        .loading-spinner {
            width: 40px;
            height: 40px;
            border: 3px solid #e5e7eb;
            border-top: 3px solid #667eea;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin-bottom: 16px;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .loading-text {
            color: #666;
            font-size: 14px;
        }
        
        .error-container {
            padding: 20px;
            text-align: center;
            color: #666;
        }
        
        .error-icon {
            font-size: 48px;
            margin-bottom: 16px;
            opacity: 0.5;
        }
        
        .error-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 8px;
            color: #333;
        }
        
        .error-desc {
            font-size: 14px;
            line-height: 1.5;
            margin-bottom: 16px;
        }
        
        .retry-btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            transition: transform 0.2s;
        }
        
        .retry-btn:hover {
            transform: translateY(-1px);
        }
        
        .settings-btn {
            background: rgba(255, 255, 255, 0.2);
            border: none;
            width: 32px;
            height: 32px;
            border-radius: 6px;
            color: white;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            margin-right: 8px;
            transition: all 0.2s;
        }
        
        .settings-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }
        
        .settings-panel {
            position: absolute;
            top: 60px;
            left: 0;
            right: 0;
            bottom: 0;
            background: white;
            border-top: 1px solid #e5e7eb;
            border-left: none;
            border-right: none;
            border-bottom: none;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            box-shadow: 0 8px 24px rgba(0,0,0,0.08);
            z-index: 20;
            overflow-y: auto;
        }
        
        .settings-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 14px 16px;
            border-bottom: 1px solid #f3f4f6;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #fff;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
        }
        
        .settings-header h3 {
            margin: 0;
            font-size: 15px;
            font-weight: 600;
            color: #fff;
        }
        
        .close-btn {
            background: rgba(255,255,255,0.2);
            border: none;
            font-size: 18px;
            color: #fff;
            cursor: pointer;
            width: 28px;
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 6px;
        }
        
        .close-btn:hover {
            background: rgba(255,255,255,0.3);
        }
        
        .settings-content {
            padding: 14px 16px 16px;
        }
        
        .setting-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid #f3f4f6;
        }
        
        .setting-item:last-child {
            border-bottom: none;
        }
        
        .setting-item label {
            font-size: 14px;
            color: #374151;
            font-weight: 500;
        }
        
        .toggle-btn, .action-btn {
            background: #f3f4f6;
            border: none;
            padding: 6px 12px;
            border-radius: 6px;
            font-size: 12px;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .toggle-btn:hover, .action-btn:hover {
            background: #e5e7eb;
        }
        
        .action-btn.primary {
            background: #667eea;
            color: white;
            box-shadow: 0 2px 8px rgba(102,126,234,0.35);
        }
        
        .action-btn.primary:hover {
            background: #5a67d8;
        }
        
        .doi-display {
            font-size: 12px;
            color: #6b7280;
            max-width: 150px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        
        .url-input {
            border: 1px solid #d1d5db;
            padding: 6px 8px;
            border-radius: 6px;
            font-size: 12px;
            width: 200px;
        }
        
        .settings-actions {
            display: flex;
            gap: 8px;
            margin-top: 16px;
            padding-top: 16px;
            border-top: 1px solid #f3f4f6;
        }
        
        /* 隐藏类 - 用于替代内联样式 */
        .hidden {
            display: none !important;
            visibility: hidden !important;
            opacity: 0 !important;
            pointer-events: none !important;
        }
        
        .hidden * {
            pointer-events: none !important;
        }
    </style>
</head>
<body>
    <div class="sidebar-header">
        <div class="header-content">
            <div class="logo">研</div>
            <div class="title-group">
                <div class="title">研学港 Researchopia</div>
                <div class="subtitle">版本 v0.1.1 | 研学并进，智慧共享</div>
            </div>
            <button class="settings-btn" id="settingsBtn" title="设置" aria-label="打开扩展设置">⚙️</button>
            <div class="status-indicator" id="connectionStatus" title="连接状态"></div>
        </div>
    </div>

    <!-- DOI 信息条（常显） -->
    <div class="info-bar" id="infoBar">
        <div class="doi-card" id="doiCard">
            <div class="doi-left">
                <span class="doi-label">检测到的 DOI</span>
                <code class="doi-code" id="doiCode">未检测到</code>
                <span class="doi-source dim" id="doiSource" aria-live="polite"></span>
            </div>
            <div class="doi-actions">
                <button class="copy-btn" id="copyDoiBtn" title="复制 DOI">复制</button>
            </div>
        </div>
    </div>
    
    <!-- 设置面板 -->
    <div class="settings-panel hidden" id="settingsPanel" aria-hidden="true">
        <div class="settings-header">
            <h3>扩展设置</h3>
            <button class="close-btn" id="closeSettingsBtn" aria-label="关闭设置面板">×</button>
        </div>
        <div class="settings-content">
            <!-- 状态卡片（来自 popup 的迁移） -->
            <div class="status-card" style="background:#f9fafb;border:1px solid #e5e7eb;border-radius:8px;padding:12px;margin-bottom:12px;">
                <div style="display:flex;justify-content:space-between;margin-bottom:6px;font-size:12px;color:#374151;">
                    <span>当前页面：</span>
                    <span id="pageStatus">检测中...</span>
                </div>
                <div style="display:flex;justify-content:space-between;font-size:12px;color:#374151;">
                    <span>DOI 检测：</span>
                    <span id="doiStatus">扫描中...</span>
                </div>
            </div>
            <div class="setting-item">
                <label>悬浮图标</label>
                <button class="toggle-btn" id="toggleFloatBtn">显示/隐藏</button>
            </div>
            <div class="setting-item">
                <label>DOI检测</label>
                <button class="action-btn" id="detectDOIBtn">重新检测</button>
            </div>
            <div class="setting-item">
                <label>当前DOI</label>
                <div class="doi-display" id="currentDOIDisplay">未检测到</div>
            </div>
            <div class="setting-item">
                <label>服务器地址</label>
                <input type="text" id="serverUrlInput" class="url-input" placeholder="https://www.researchopia.com/">
            </div>
            <div class="setting-item">
                <label>快速搜索</label>
                <button class="action-btn primary" id="searchInResearchopiaBtn">在研学港中搜索</button>
            </div>
            <div class="setting-item">
                <label>打开网站</label>
                <button class="action-btn" id="openWebsiteBtn">在新标签打开</button>
            </div>
            <div class="setting-item">
                <label>内容</label>
                <button class="action-btn" id="refreshBtn">刷新侧边栏内容</button>
            </div>
            <div class="settings-actions">
                <button class="action-btn primary" id="saveSettingsBtn">保存设置</button>
                <button class="action-btn" id="resetSettingsBtn">重置</button>
            </div>
        </div>
    </div>
    
    <div class="iframe-container">
        <div class="loading-overlay" id="loadingOverlay">
            <div class="loading-spinner"></div>
            <div class="loading-text">正在加载研学港...</div>
        </div>
        
        <div class="error-container hidden" id="errorContainer" aria-hidden="true">
            <div class="error-icon">🔌</div>
            <div class="error-title">连接失败</div>
            <div class="error-desc">
                无法连接到研学港服务器<br>
                请确保本地服务器正在运行
            </div>
            <button class="retry-btn" id="retryBtn">重试连接</button>
        </div>
        
        <iframe id="researchopiaFrame" class="hidden"></iframe>
    </div>
    
    <script src="sidebar.js"></script>
</body>
</html>